using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Microsoft.ApplicationBlocks.Data;
using NCS.Library;
using NCS.Library.Utilities;
using NCS.Module.Multimedia.Library.Gallery;
using NCS.Module.Multimedia.Library.Bonus;
using NCS.Module.Multimedia.Library.Video;

namespace NCS.Module.Multimedia.Library.Providers
{
    public class SqlDataProvider : DataAccessProvider
    {
        private string connectionString = string.Empty;
        public string ConnectionString
        {
            get { return this.connectionString; }
            set { this.connectionString = value; }
        }
        public SqlDataProvider(string strConn)
        {
            this.ConnectionString = strConn;
        }

        #region catebonus
        //catebonus
        public override DataTable GetCateBonus()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_CateBonus_GetAvailables", AppEnv.GetLanguage(), AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }



        public override DataTable GetCateBonusByNum(int num)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_CateBonusGetAvailablesByNum", AppEnv.GetLanguage(), num, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllCateBonus()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_CateBonus_GetAll", AppEnv.GetLanguage(), AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllCateBonusbyOther(string txtSearch, DateTime fromdate, DateTime todate, int userid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_CateBonus_GetAllByOtherByKey", AppEnv.GetLanguage(), txtSearch, fromdate, todate, userid, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable GetAllCateBonusByParentID(int _catebonus_parentID)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_CateBonus_GetAllByParentID", _catebonus_parentID, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable GetAllCateBonusByParentID(int _catebonus_parentID, int portalid, int pagesize, int currpage, out int totalRecord)
        {
            DataTable retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Gallery_CateBonus_GetAllByParentID1", dbConn);
            dbCmd.Parameters.AddWithValue("@CateBonusParentID", _catebonus_parentID);
            dbCmd.Parameters.AddWithValue("@PortalID", portalid);
            dbCmd.Parameters.AddWithValue("@PageSize", pagesize);
            dbCmd.Parameters.AddWithValue("@CurrentPage", currpage);
            dbCmd.Parameters.Add(new SqlParameter("@TotalRecord", SqlDbType.Int));
            dbCmd.Parameters["@TotalRecord"].Direction = ParameterDirection.Output;
            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
                totalRecord = Convert.ToInt32(dbCmd.Parameters["@TotalRecord"].Value);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public override void SetCateBonusIndex(int id, int index)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_CateBonus_SetIndex", id, index);
        }

        public override void SetCateBonusRank(int id, int rank)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_CateBonus_SetRank", id, rank);
        }
        public override void SetCateBonusStatus(int id, bool status)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_CateBonus_SetStatus", id, status);
        }
        public override void DeleteCateBonus(int _CateBonus_ID)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_CateBonus_Delete", _CateBonus_ID);
        }
        public override int InsertCateBonus(Gallery_CateBonusInfo _CateBonusInfo)
        {
            return (int)SqlHelper.ExecuteScalar(this.ConnectionString, "Gallery_CateBonus_Insert", _CateBonusInfo.CateBonusParentID, _CateBonusInfo.CateBonusAvatar, _CateBonusInfo.CateBonusName, _CateBonusInfo.CateBonusDetail, _CateBonusInfo.CreateUserID, _CateBonusInfo.ModifyUserID, _CateBonusInfo.IsComment, _CateBonusInfo.PortalID, AppEnv.GetLanguage(), _CateBonusInfo.Other_ID, _CateBonusInfo.Rank);
        }
        public override void UpdateCateBonus(Gallery_CateBonusInfo _CateBonusInfo)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_CateBonus_Update", _CateBonusInfo.CateBonusID, _CateBonusInfo.CateBonusParentID, _CateBonusInfo.CateBonusAvatar, _CateBonusInfo.CateBonusName, _CateBonusInfo.CateBonusDetail, _CateBonusInfo.CreateUserID, _CateBonusInfo.ModifyUserID, _CateBonusInfo.IsComment, _CateBonusInfo.PortalID, AppEnv.GetLanguage(), _CateBonusInfo.Other_ID, _CateBonusInfo.Rank);
        }
        public override Gallery_CateBonusInfo GetCateBonus(int _CateBonus_ID)
        {
            IDataReader dr = SqlHelper.ExecuteReader(this.ConnectionString, "Gallery_CateBonus_GetInfo", _CateBonus_ID);
            Gallery_CateBonusInfo bonus = (Gallery_CateBonusInfo)ObjectHelper.CreateObject(typeof(Gallery_CateBonusInfo), dr);
            return bonus;
        }

        public override Gallery_CateBonusInfo GetCateBonusByOtherID(int otherid)
        {
            IDataReader dr = SqlHelper.ExecuteReader(this.ConnectionString, "Gallery_CateBonus_GetInfoByOtherID", otherid);
            Gallery_CateBonusInfo bonus = (Gallery_CateBonusInfo)ObjectHelper.CreateObject(typeof(Gallery_CateBonusInfo), dr);
            return bonus;
        }

        #endregion
        #region Bonus

        public override DataTable GetBonus()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_GetAvailables", AppEnv.GetLanguage());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable GetAllBonusByKey(string txtSearch, DateTime fromdate, DateTime todate, int userid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_GetAllBonusByKey", AppEnv.GetLanguage(), txtSearch, fromdate, todate, userid, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable GetAllBonusByNum(int num)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_GetAvailablesByNum", AppEnv.GetLanguage(), num);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllBonus()
        {
            // mr Nguyen Edit  12/03/2008
            //DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_GetAll", AppEnv.GetLanguage());

            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_GetAll", AppEnv.PortalId());

            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable GetAllCateBonusID(int _catebonus_parentID)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_GetAllByAlbumID", _catebonus_parentID);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable GetTopBonus(int num, int type)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_GetTopByType", num, type, AppEnv.GetLanguage());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetTopBonus(int portalid, int pagesize, int currpage, out int totalRecord, int type)
        {
            DataTable retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Gallery_Bonus_GetAll", dbConn);
            dbCmd.Parameters.AddWithValue("@PortalID", portalid);
            dbCmd.Parameters.AddWithValue("@PageSize", pagesize);
            dbCmd.Parameters.AddWithValue("@CurrentPage", currpage);
            dbCmd.Parameters.AddWithValue("@Type", type);
            dbCmd.Parameters.Add(new SqlParameter("@TotalRecord", SqlDbType.Int));
            dbCmd.Parameters["@TotalRecord"].Direction = ParameterDirection.Output;
            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
                totalRecord = Convert.ToInt32(dbCmd.Parameters["@TotalRecord"].Value);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }

        public override void SetBonusIndex(int id, int index)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_SetIndex", id, index);
        }

        public override void SetBonusRank(int id, int rank)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_SetRank", id, rank);
        }
        public override void SetBonusStatus(int id, bool status)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_SetStatus", id, status);
        }
        public override void DeleteBonus(int _bonus_ID)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_Delete", _bonus_ID);
        }
        public override int InsertBonus(Gallery_BonusInfo _bonusInfo)
        {
            return (int)SqlHelper.ExecuteScalar(this.ConnectionString, "Gallery_Bonus_Insert", _bonusInfo.BonusType, _bonusInfo.BonusName, _bonusInfo.BonusAvatar, _bonusInfo.BonusDescription, _bonusInfo.BonusCopyLink, _bonusInfo.BonusUploadLink, _bonusInfo.CreateUserID, _bonusInfo.ModifyUserID, _bonusInfo.IsComment, _bonusInfo.Visible, _bonusInfo.Lang, _bonusInfo.Rank, _bonusInfo.CateBonusID, _bonusInfo.PortalID);
        }
        public override void UpdateBonus(Gallery_BonusInfo _bonusInfo)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Bonus_Update", _bonusInfo.BonusID, _bonusInfo.BonusType, _bonusInfo.BonusName, _bonusInfo.BonusAvatar, _bonusInfo.BonusDescription, _bonusInfo.BonusCopyLink, _bonusInfo.BonusUploadLink, _bonusInfo.CreateUserID, _bonusInfo.ModifyUserID, _bonusInfo.IsComment, _bonusInfo.Visible, _bonusInfo.Lang, _bonusInfo.Rank, _bonusInfo.CateBonusID, _bonusInfo.PortalID);
        }
        public override Gallery_BonusInfo GetBonus(int _bonus_ID)
        {
            IDataReader dr = SqlHelper.ExecuteReader(this.ConnectionString, "Gallery_Bonus_GetInfo", _bonus_ID);
            Gallery_BonusInfo bonus = (Gallery_BonusInfo)ObjectHelper.CreateObject(typeof(Gallery_BonusInfo), dr);
            return bonus;
        }

        #endregion

        #region Gallery

        public override DataTable GetAlbum()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_GetAvailables", AppEnv.GetLanguage(), AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override string GetAlbumName(int albumid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_GetAlbumName", albumid);
            DataTable tbl = null;
            if (ds != null && ds.Tables.Count > 0) tbl = ds.Tables[0];

            if (tbl != null && tbl.Rows.Count > 0)
                return ConvertUtility.ToString(tbl.Rows[0][0]);
            else
                return string.Empty;
        }

        public override DataTable GetAllGalleryByKey(string txtSearch, DateTime fromdate, DateTime todate, int userid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_GetAllGalleryByKey", AppEnv.GetLanguage(), txtSearch, fromdate, todate, userid, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable GetAlbumByNum(int num)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_GetAvailablesByNum", AppEnv.GetLanguage(), num, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllAlbum()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_GetAll", AppEnv.GetLanguage(), AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllAlbum(int start, int end, int total)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_GetAllByPage", AppEnv.GetLanguage(), AppEnv.PortalId(), start, end, total);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllAlbumbyOther(string txtSearch, DateTime fromdate, DateTime todate, int userid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_GetAllByOtherByKey", AppEnv.GetLanguage(), txtSearch, fromdate, todate, userid, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllAlbumbyOther()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_GetAllByOther", AppEnv.GetLanguage(), AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllAlbumByParentID(int _album_parentID)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_GetAllByParentID", _album_parentID, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable GetAllAlbumByParentID(int _album_parentID, int portalid, int pagesize, int currpage, out int totalRecord)
        {
            DataTable retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Gallery_Album_GetAllByParentID1", dbConn);
            dbCmd.Parameters.AddWithValue("@AlbumParentID", _album_parentID);
            dbCmd.Parameters.AddWithValue("@PortalID", portalid);
            dbCmd.Parameters.AddWithValue("@PageSize", pagesize);
            dbCmd.Parameters.AddWithValue("@CurrentPage", currpage);
            dbCmd.Parameters.Add(new SqlParameter("@TotalRecord", SqlDbType.Int));
            dbCmd.Parameters["@TotalRecord"].Direction = ParameterDirection.Output;
            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
                totalRecord = Convert.ToInt32(dbCmd.Parameters["@TotalRecord"].Value);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public override void SetAlbumIndex(int id, int index)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_SetIndex", id, index);
        }

        public override void SetAlbumRank(int id, int rank)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_SetRank", id, rank);
        }
        public override void SetAlbumStatus(int id, bool status)
        {
           // SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_SetStatus", id, status);
            int status_item = 0;
            if (status)
                status_item = 1;
            else status_item = 0;
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_SetStatus", id, status_item);
        }
        public override void DeleteAlbum(int _Album_ID)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_Delete", _Album_ID);
        }
        public override int InsertAlbum(Gallery_AlbumInfo _AlbumInfo)
        {
            return (int)SqlHelper.ExecuteScalar(this.ConnectionString, "Gallery_Album_Insert", _AlbumInfo.AlbumParentID, _AlbumInfo.AlbumAvatar, _AlbumInfo.AlbumName, _AlbumInfo.AlbumDetail, _AlbumInfo.CreateUserID, _AlbumInfo.ModifyUserID, _AlbumInfo.IsComment, _AlbumInfo.PortalID, AppEnv.GetLanguage(), _AlbumInfo.Other_ID, _AlbumInfo.Rank, _AlbumInfo.Visible);
        }
        public override void UpdateAlbum(Gallery_AlbumInfo _AlbumInfo)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Album_Update", _AlbumInfo.AlbumID, _AlbumInfo.AlbumParentID, _AlbumInfo.AlbumAvatar, _AlbumInfo.AlbumName, _AlbumInfo.AlbumDetail, _AlbumInfo.CreateUserID, _AlbumInfo.ModifyUserID, _AlbumInfo.IsComment, _AlbumInfo.PortalID, AppEnv.GetLanguage(), _AlbumInfo.Other_ID, _AlbumInfo.Rank, _AlbumInfo.Visible);
        }
        public override Gallery_AlbumInfo GetAlbum(int _Album_ID)
        {
            IDataReader dr = SqlHelper.ExecuteReader(this.ConnectionString, "Gallery_Album_GetInfo", _Album_ID);
            Gallery_AlbumInfo bonus = (Gallery_AlbumInfo)ObjectHelper.CreateObject(typeof(Gallery_AlbumInfo), dr);
            return bonus;
        }

        public override Gallery_AlbumInfo GetAlbumByOtherID(int otherid)
        {
            IDataReader dr = SqlHelper.ExecuteReader(this.ConnectionString, "Gallery_Album_GetInfoByOtherID", otherid);
            Gallery_AlbumInfo bonus = (Gallery_AlbumInfo)ObjectHelper.CreateObject(typeof(Gallery_AlbumInfo), dr);
            return bonus;
        }

        //Picture
        public override PictureInfo GetPicture(int picid)
        {
            IDataReader dr = SqlHelper.ExecuteReader(this.connectionString, "Gallery_Picture_GetInfo", picid);
            PictureInfo picture = (PictureInfo)ObjectHelper.CreateObject(typeof(PictureInfo), dr);
            return picture;
        }
        public override int Picture_Insert(PictureInfo picture)
        {
            return (int)SqlHelper.ExecuteScalar(this.connectionString, "Gallery_Picture_Insert", picture.PicName, picture.PicAvatar, picture.PicDetail, picture.PicIndex, picture.PicVisible, picture.CreateUserID, picture.ModifyUserID, picture.AlbumID, picture.PortalID);
        }
        public override void Picture_Update(PictureInfo picture)
        {
            SqlHelper.ExecuteDataset(this.connectionString, "Gallery_Picture_Update", picture.PicID, picture.PicName, picture.PicAvatar, picture.PicDetail, picture.PicIndex, picture.PicVisible, picture.CreateDate, picture.ModifiedDate, picture.CreateUserID, picture.ModifyUserID, picture.AlbumID, picture.PortalID);
        }
        public override void Picture_Delete(int picid)
        {
            SqlHelper.ExecuteDataset(this.connectionString, "Gallery_Picture_Delete", picid);
        }

        public override DataTable Picture_GetAll(int portalid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Picture_GetAll", portalid);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable Picture_GetAllByAlbumID(int albumid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Picture_GetAllByAlbumID", albumid);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable Picture_GetAllByAlbumIDAndVisible(int albumid, int visible)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Gallery_Picture_GetAllByAlbumIDAndVisible", albumid, visible);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override void Picture_SetIndex(int picid, int index)
        {
            SqlHelper.ExecuteDataset(this.connectionString, "Gallery_Picture_SetIndex", picid, index);
        }
        #endregion

        #region Video Clip
        //Album Video
        public override DataTable GetAlbumVideo()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_GetAvailables", AppEnv.GetLanguage(), AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override string GetAlbumVideoName(int albumid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_GetAlbumName", albumid);
            DataTable tbl = null;
            if (ds != null && ds.Tables.Count > 0) tbl = ds.Tables[0];

            if (tbl != null && tbl.Rows.Count > 0)
                return ConvertUtility.ToString(tbl.Rows[0][0]);
            else
                return string.Empty;
        }

        public override DataTable GetAllVideoByKey(string txtSearch, DateTime fromdate, DateTime todate, int userid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_GetAllVideoByKey", AppEnv.GetLanguage(), txtSearch, fromdate, todate, userid, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable GetAlbumVideoByNum(int num)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_GetAvailablesByNum", AppEnv.GetLanguage(), num, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllAlbumVideo()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_GetAll", AppEnv.GetLanguage(), AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllAlbumVideo(int start, int end, int total)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_GetAllByPage", AppEnv.GetLanguage(), AppEnv.PortalId(), start, end, total);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllAlbumVideobyOther(string txtSearch, DateTime fromdate, DateTime todate, int userid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_GetAllByOtherByKey", AppEnv.GetLanguage(), txtSearch, fromdate, todate, userid, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllAlbumVideobyOther()
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_GetAllByOther", AppEnv.GetLanguage(), AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable GetAllAlbumVideoByParentID(int _album_parentID)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_GetAllByParentID", _album_parentID, AppEnv.PortalId());
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable GetAllAlbumVideoByParentID(int _album_parentID, int portalid, int pagesize, int currpage, out int totalRecord)
        {
            DataTable retVal = null;
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Video_Album_GetAllByParentID1", dbConn);
            dbCmd.Parameters.AddWithValue("@AlbumParentID", _album_parentID);
            dbCmd.Parameters.AddWithValue("@PortalID", portalid);
            dbCmd.Parameters.AddWithValue("@PageSize", pagesize);
            dbCmd.Parameters.AddWithValue("@CurrentPage", currpage);
            dbCmd.Parameters.Add(new SqlParameter("@TotalRecord", SqlDbType.Int));
            dbCmd.Parameters["@TotalRecord"].Direction = ParameterDirection.Output;
            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
                totalRecord = Convert.ToInt32(dbCmd.Parameters["@TotalRecord"].Value);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public override void SetAlbumVideoIndex(int id, int index)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_SetIndex", id, index);
        }

        public override void SetAlbumVideoRank(int id, int rank)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_SetRank", id, rank);
        }
        public override void SetAlbumVideoStatus(int id, bool status)
        {
            int status_item = 0;
            if (status)
                status_item = 1;
            else status_item = 0;
            SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_SetStatus", id, status_item);
        }
        public override void DeleteAlbumVideo(int _Album_ID)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_Delete", _Album_ID);
        }
        public override int InsertAlbumVideo(Video_AlbumInfo _AlbumInfo)
        {
            return (int)SqlHelper.ExecuteScalar(this.ConnectionString, "Video_Album_Insert", _AlbumInfo.AlbumParentID, _AlbumInfo.AlbumAvatar, _AlbumInfo.AlbumName, _AlbumInfo.AlbumDetail, _AlbumInfo.CreateUserID, _AlbumInfo.ModifyUserID, _AlbumInfo.IsComment, _AlbumInfo.PortalID, AppEnv.GetLanguage(), _AlbumInfo.Other_ID, _AlbumInfo.Rank, _AlbumInfo.Visible);
        }
        public override void UpdateAlbumVideo(Video_AlbumInfo _AlbumInfo)
        {
            SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Album_Update", _AlbumInfo.AlbumID, _AlbumInfo.AlbumParentID, _AlbumInfo.AlbumAvatar, _AlbumInfo.AlbumName, _AlbumInfo.AlbumDetail, _AlbumInfo.CreateUserID, _AlbumInfo.ModifyUserID, _AlbumInfo.IsComment, _AlbumInfo.PortalID, AppEnv.GetLanguage(), _AlbumInfo.Other_ID, _AlbumInfo.Rank, _AlbumInfo.Visible);
        }
        public override Video_AlbumInfo GetAlbumVideo(int _Album_ID)
        {
            IDataReader dr = SqlHelper.ExecuteReader(this.ConnectionString, "Video_Album_GetInfo", _Album_ID);
            Video_AlbumInfo bonus = (Video_AlbumInfo)ObjectHelper.CreateObject(typeof(Video_AlbumInfo), dr);
            return bonus;
        }

        public override Video_AlbumInfo GetAlbumVideoByOtherID(int otherid)
        {
            IDataReader dr = SqlHelper.ExecuteReader(this.ConnectionString, "Video_Album_GetInfoByOtherID", otherid);
            Video_AlbumInfo bonus = (Video_AlbumInfo)ObjectHelper.CreateObject(typeof(Video_AlbumInfo), dr);
            return bonus;
        }
        //Clip
        public override ClipInfo GetClip(int clipid)
        {
            IDataReader dr = SqlHelper.ExecuteReader(this.connectionString, "Video_Clip_GetInfo", clipid);
            ClipInfo clip = (ClipInfo)ObjectHelper.CreateObject(typeof(ClipInfo), dr);
            return clip;
        }
        public override int Clip_Insert(ClipInfo clip)
        {
            return (int)SqlHelper.ExecuteScalar(this.connectionString, "Video_Clip_Insert", clip.ClipName, clip.ClipAvatar, clip.ClipFile, clip.ClipDetail, clip.ClipIndex, clip.ClipVisible, clip.CreateUserID, clip.ModifyUserID, clip.AlbumID, clip.PortalID);
        }
        public override void Clip_Update(ClipInfo clip)
        {
            SqlHelper.ExecuteDataset(this.connectionString, "Video_Clip_Update", clip.ClipID, clip.ClipName, clip.ClipAvatar, clip.ClipFile, clip.ClipDetail, clip.ClipIndex, clip.ClipVisible, clip.CreateDate, clip.ModifiedDate, clip.CreateUserID, clip.ModifyUserID, clip.AlbumID, clip.PortalID);
        }
        public override void Clip_Delete(int clipid)
        {
            SqlHelper.ExecuteDataset(this.connectionString, "Video_Clip_Delete", clipid);
        }

        public override DataTable Clip_GetAll(int portalid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Clip_GetAll", portalid);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }

        public override DataTable Clip_GetAllByAlbumID(int albumid)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Clip_GetAllByAlbumID", albumid);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override DataTable Clip_GetAllByAlbumIDAndVisible(int albumid, int visible)
        {
            DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "Video_Clip_GetAllByAlbumIDAndVisible", albumid, visible);
            if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
            return null;
        }
        public override void Clip_SetIndex(int clipid, int index)
        {
            SqlHelper.ExecuteDataset(this.connectionString, "Video_Clip_SetIndex", clipid, index);
        }
        #endregion
    }
}
